package com.example.edianzu.somur.module.mine.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;
import android.widget.FrameLayout;

import com.example.edianzu.somur.App;
import com.example.edianzu.somur.R;
import com.example.edianzu.somur.api.bean.LoginInfo;
import com.example.edianzu.somur.login.mvp.view.LoginActivity;
import com.example.edianzu.somur.utils.content.FormatDate;
import com.example.edianzu.somur.utils.content.StatusBarUtils;
import com.example.edianzu.somur.utils.manager.ActivityManager;
import com.example.edianzu.somur.utils.view.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PersonalCenterActivity extends BaseActivity {

    @BindView(R.id.fragment_mine)
    AppCompatImageView fragmentMine;
    @BindView(R.id.activity_personalcenter_name)
    AppCompatTextView activityPersonalcenterName;
    @BindView(R.id.activity_personalcenter_name_content)
    AppCompatTextView activityPersonalcenterNameContent;
    @BindView(R.id.activity_personalcenter_name_back)
    AppCompatImageView activityPersonalcenterNameBack;
    @BindView(R.id.fragment_exercise_view_0)
    FrameLayout fragmentExerciseView0;
    @BindView(R.id.activity_personalcenter_sex)
    AppCompatTextView activityPersonalcenterSex;
    @BindView(R.id.activity_personalcenter_sex_content)
    AppCompatTextView activityPersonalcenterSexContent;
    @BindView(R.id.activity_personalcenter_sex_back)
    AppCompatImageView activityPersonalcenterSexBack;
    @BindView(R.id.fragment_exercise_view_1)
    FrameLayout fragmentExerciseView1;
    @BindView(R.id.activity_personalcenter_brithday)
    AppCompatTextView activityPersonalcenterBrithday;
    @BindView(R.id.activity_personalcenter_brithday_content)
    AppCompatTextView activityPersonalcenterBrithdayContent;
    @BindView(R.id.activity_personalcenter_brithday_back)
    AppCompatImageView activityPersonalcenterBrithdayBack;
    @BindView(R.id.fragment_exercise_view_2)
    FrameLayout fragmentExerciseView2;
    @BindView(R.id.activity_personalcenter_phone)
    AppCompatTextView activityPersonalcenterPhone;
    @BindView(R.id.activity_personalcenter_phone_content)
    AppCompatTextView activityPersonalcenterPhoneContent;
    @BindView(R.id.activity_personalcenter_phone_back)
    AppCompatImageView activityPersonalcenterPhoneBack;
    @BindView(R.id.activity_personalcenter_alter)
    AppCompatButton activityPersonalcenterAlter;
    @BindView(R.id.activity_personalcenter_exit)
    AppCompatButton activityPersonalcenterExit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.setWindowStatusBarColor(this,R.color.title);
        setContentView(R.layout.activity_personal_center);

        ButterKnife.bind(this);

        LoginInfo loginInfo = (LoginInfo) getIntent().getSerializableExtra("loginInfo");
        if (loginInfo != null) {

            activityPersonalcenterNameContent.setText(loginInfo.getData().getName());
            switch (loginInfo.getData().getSex()) {

                case 0:
                    activityPersonalcenterSexContent.setText("女");
                    break;
                case 1:
                    activityPersonalcenterSexContent.setText("男");
                    break;
            }
            activityPersonalcenterBrithdayContent.setText(FormatDate.getStringDateMonth(loginInfo.getData().getBirthday(),1+"",1+"",1+"",3+""));
            activityPersonalcenterPhoneContent.setText(loginInfo.getData().getMobile());
        }
    }

    @OnClick({R.id.fragment_mine, R.id.activity_personalcenter_name_back, R.id.activity_personalcenter_sex_back, R.id.activity_personalcenter_brithday_back, R.id.activity_personalcenter_phone_back, R.id.activity_personalcenter_alter, R.id.activity_personalcenter_exit})
    public void onViewClicked(View view) {

        Intent intent=new Intent();
        switch (view.getId()) {
            case R.id.fragment_mine:

                finish();
                break;
            case R.id.activity_personalcenter_name_back:
                break;
            case R.id.activity_personalcenter_sex_back:
                break;
            case R.id.activity_personalcenter_brithday_back:
                break;
            case R.id.activity_personalcenter_phone_back:
                break;
            case R.id.activity_personalcenter_alter:

                intent.setClass(PersonalCenterActivity.this, RevisePasswordActivity.class);
                intent.putExtra("member_id",getIntent().getIntExtra("member_id",0));
                startActivity(intent);
                break;
            case R.id.activity_personalcenter_exit:

                intent.setClass(PersonalCenterActivity.this, LoginActivity.class);
                startActivity(intent);
//                结束之前的Activity退回到LoginActivity
                ActivityManager.finishAll();
                /*//删除SharedPreferences文件
                File file= new File("/data/data/"+getPackageName().toString()+"/shared_prefs","config.xml");
                if(file.exists())
                {
                    file.delete();
                    Toast.makeText(PersonalCenterActivity.this, "删除成功", Toast.LENGTH_LONG).show();
                }*/
                //清空删除SharedPreferences数据
                SharedPreferences sharedPreferences = App.getApp().getSharedPreferences();
                if(sharedPreferences!=null){
                    sharedPreferences.edit().clear().apply();
                }
                finish();
                break;
        }
    }
}
